﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Tanmia.Basis.Prism;

namespace Tanmia.Basis.View
{
    /// <summary>
    /// Interaction logic for Window3.xaml
    /// </summary>
    public partial class EditorWindow : BaseWindow
    {
        public FrameworkElement EditorUserControl
        {
            get { return contentPresenter.Content as FrameworkElement; }
            set { contentPresenter.Content = value; }
        }

        private OperationButton CoreAddUICommand(UICommand command)
        {
            InputBindings.Add(new InputBinding(command, new KeyGesture(command.GestureKey, command.GestureModifier)));
            OperationButton opBtn = new OperationButton();
            opBtn.SetCommand(command);
            operationList.Items.Add(opBtn);

            return opBtn;
        }

        public void AddFirstUICommand(UICommand command)
        {
            OperationButton opBtn = CoreAddUICommand(command);
            opBtn.SetCornerRadius(0, 4, 0, 0);
        }

        public void AddUICommand(UICommand command)
        {
            CoreAddUICommand(command);
        }

        public void AddLastUICommand(UICommand command)
        {
            OperationButton opBtn = CoreAddUICommand(command);
            opBtn.SetBorderThickness(1, 1, 1, 1);
            opBtn.SetCornerRadius(0, 0, 4, 0);
        }

        public void AddSeparator()
        {
            Separator sep = new Separator();
            operationList.Items.Add(sep);
        }

        public EditorWindow()
        {
            InitializeComponent();
        }

        private void MaxAndNormalButton_Toggle(object sender, RoutedEventArgs e)
        {
            if (MaxAndNormalButton.IsChecked.HasValue && MaxAndNormalButton.IsChecked.Value)
                MaximizeWindow();
            else
                NormalizeWindow();
        }

        private void MinButton_Click(object sender, RoutedEventArgs e)
        {
            MinimizeWindow();
        }

        private void CaptionBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (e.ClickCount == 1)
                DraggingWindow(e);
            else if (e.ClickCount == 2)
                if (MaxAndNormalButton.IsChecked.Value)
                    MaxAndNormalButton.IsChecked = false;
                else
                    MaxAndNormalButton.IsChecked = true;
        }
    }
}
